package com.rzdata.poct.web.controller.business;

import com.rzdata.poct.common.annotation.Log;
import com.rzdata.poct.common.annotation.RepeatSubmit;
import com.rzdata.poct.common.core.controller.BaseController;
import com.rzdata.poct.common.core.domain.AjaxResult;
import com.rzdata.poct.common.core.page.TableDataInfo;
import com.rzdata.poct.common.core.validate.AddGroup;
import com.rzdata.poct.common.core.validate.EditGroup;
import com.rzdata.poct.common.core.validate.QueryGroup;
import com.rzdata.poct.common.enums.BusinessType;
import com.rzdata.poct.common.utils.poi.ExcelUtil;
import com.rzdata.poct.system.domain.business.bo.PoctQualityRulesBo;
import com.rzdata.poct.system.domain.business.po.PoctQualityRules;
import com.rzdata.poct.system.domain.business.vo.PoctQualityRulesVo;
import com.rzdata.poct.system.service.IPoctQualityRulesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2021-09-09
 */
@Validated
@Api(value = "质控规则表控制器", tags = {"质控规则表管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/qualityRules")
public class PoctQualityRulesController extends BaseController {

    private final IPoctQualityRulesService iPoctQualityRulesService;

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation("查询质控规则表列表")
    @PreAuthorize("@ss.hasPermi('system:qualityRules:list')")
    @PostMapping("/list")
    public TableDataInfo<PoctQualityRulesVo> list(@RequestBody PoctQualityRulesBo bo) {
        return iPoctQualityRulesService.queryPageList(bo);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation("导出质控规则表列表")
    @PreAuthorize("@ss.hasPermi('system:qualityRules:export')")
    @Log(title = "导出质控规则表列表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated PoctQualityRulesBo bo, HttpServletResponse response) {
        List<PoctQualityRulesVo> list = iPoctQualityRulesService.queryList(bo);
        ExcelUtil.exportExcel(list, "导出质控规则表列表", PoctQualityRulesVo.class, response);
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @ApiOperation("获取质控规则表详细信息")
    @PreAuthorize("@ss.hasPermi('system:qualityRules:query')")
    @GetMapping("/{id}")
    public AjaxResult<PoctQualityRulesVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iPoctQualityRulesService.queryById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("新增质控规则表")
    @PreAuthorize("@ss.hasPermi('system:qualityRules:add')")
    @Log(title = "新增质控规则表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody PoctQualityRulesBo bo) {
        return toAjax(iPoctQualityRulesService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation("修改质控规则表")
    @PreAuthorize("@ss.hasPermi('system:qualityRules:edit')")
    @Log(title = "修改质控规则表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody PoctQualityRulesBo bo) {
        return toAjax(iPoctQualityRulesService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation("删除质控规则表")
    @PreAuthorize("@ss.hasPermi('system:qualityRules:remove')")
    @Log(title = "删除质控规则表" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPoctQualityRulesService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation("作废")
    @Log(title = "作废" , businessType = BusinessType.DELETE)
    @GetMapping("/cancelById/{id}")
    public AjaxResult<Void> cancelById(@PathVariable("id") Long id) {
        return toAjax(iPoctQualityRulesService.cancelById(id) ? 1 : 0);
    }

    /**
     * 查询质控规则列表（
     */
    @ApiOperation("查询质控规则列表")
    @PreAuthorize("@ss.hasPermi('system:qualityRules:rulesList')")
    @PostMapping("/rulesList")
    public TableDataInfo<PoctQualityRulesVo> rulesList(@RequestBody PoctQualityRules bo) {
        return iPoctQualityRulesService.queryPageRulesList(bo);
    }
}
